<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::PKey::RSA - openssl: Ruby Standard Library Documentation</title>


<script src="../../js/navigation.js" defer></script>
<script src="../../js/search.js" defer></script>
<script src="../../js/search_index.js" defer></script>
<script src="../../js/searcher.js" defer></script>
<script src="../../js/darkfish.js" defer></script>

<script src="../../js/jquery-3.2.0.min.js"></script>

<script src="../../js/vue.min.js"></script>
<script src="../../js/js.cookie.min.js"></script>

<link href="../../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../../css/rdoc.css" rel="stylesheet">
<link href="../../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
  var index_rel_prefix = "../../";
  var darkModeCsseHref = "../../css/rdoc-dm.css"
  var defaultModeCssHref = "../../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="PKey.html">OpenSSL::PKey::PKey</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="../Marshal.html">OpenSSL::Marshal</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-generate">::generate</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-export">#export</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-params">#params</a>
    <li ><a href="#method-i-private-3F">#private?</a>
    <li ><a href="#method-i-private_decrypt">#private_decrypt</a>
    <li ><a href="#method-i-private_encrypt">#private_encrypt</a>
    <li ><a href="#method-i-public-3F">#public?</a>
    <li ><a href="#method-i-public_decrypt">#public_decrypt</a>
    <li ><a href="#method-i-public_encrypt">#public_encrypt</a>
    <li ><a href="#method-i-public_key">#public_key</a>
    <li ><a href="#method-i-set_crt_params">#set_crt_params</a>
    <li ><a href="#method-i-set_factors">#set_factors</a>
    <li ><a href="#method-i-set_key">#set_key</a>
    <li ><a href="#method-i-sign_pss">#sign_pss</a>
    <li ><a href="#method-i-to_der">#to_der</a>
    <li ><a href="#method-i-to_pem">#to_pem</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-translate_padding_mode">#translate_padding_mode</a>
    <li ><a href="#method-i-verify_pss">#verify_pss</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenSSL::PKey::RSA">
    <h1 id="class-OpenSSL::PKey::RSA" class="class">
      class OpenSSL::PKey::RSA
    </h1>

    <section class="description">
    
<p><a href="RSA.html"><code>RSA</code></a> is an asymmetric public key algorithm that has been formalized in RFC 3447. It is in widespread use in public key infrastructures (PKI) where certificates (cf. <a href="../X509/Certificate.html"><code>OpenSSL::X509::Certificate</code></a>) often are issued on the basis of a public/private <a href="RSA.html"><code>RSA</code></a> key pair. <a href="RSA.html"><code>RSA</code></a> is used in a wide field of applications such as secure (symmetric) key exchange, e.g. when establishing a secure TLS/SSL connection. It is also used in various digital signature schemes.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="NO_PADDING">NO_PADDING
          <dd>
          <dt id="PKCS1_OAEP_PADDING">PKCS1_OAEP_PADDING
          <dd>
          <dt id="PKCS1_PADDING">PKCS1_PADDING
          <dd>
          <dt id="SSLV23_PADDING">SSLV23_PADDING
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-generate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          generate(size, exponent = 65537) &rarr; RSA
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Generates an RSA keypair.</p>

<p>See also <a href="../PKey.html#method-c-generate_key"><code>OpenSSL::PKey.generate_key</code></a>.</p>
<dl class="rdoc-list note-list"><dt><code>size</code>
<dd>
<p>The desired key size in bits.</p>
</dd><dt><code>exponent</code>
<dd>
<p>An odd <a href="../../Integer.html"><code>Integer</code></a>, normally 3, 17, or 65537.</p>
</dd></dl>

                              <div class="method-source-code" id="generate-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 343</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">generate</span>(<span class="ruby-identifier">size</span>, <span class="ruby-identifier">exp</span> = <span class="ruby-value">0x10001</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">blk</span>)
  <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span>.<span class="ruby-identifier">generate_key</span>(<span class="ruby-string">&quot;RSA&quot;</span>, {
    <span class="ruby-string">&quot;rsa_keygen_bits&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">size</span>,
    <span class="ruby-string">&quot;rsa_keygen_pubexp&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">exp</span>,
  }, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">blk</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new &rarr; rsa
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(encoded_key [, password ]) &rarr; rsa
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(encoded_key) { password } &rarr; rsa
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(size [, exponent]) &rarr; rsa
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Generates or loads an RSA keypair.</p>

<p>If called without arguments, creates a new instance with no key components set. They can be set individually by <a href="RSA.html#method-i-set_key"><code>set_key</code></a>, <a href="RSA.html#method-i-set_factors"><code>set_factors</code></a>, and <a href="RSA.html#method-i-set_crt_params"><code>set_crt_params</code></a>.</p>

<p>If called with a String, tries to parse as DER or PEM encoding of an RSA key. Note that if <em>password</em> is not specified, but the key is encrypted with a password, OpenSSL will prompt for it. See also <a href="../PKey.html#method-c-read"><code>OpenSSL::PKey.read</code></a> which can parse keys of any kind.</p>

<p>If called with a number, generates a new key pair. This form works as an alias of <a href="RSA.html#method-c-generate"><code>RSA.generate</code></a>.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">2048</span>
<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>.<span class="ruby-identifier">new</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span> <span class="ruby-string">&#39;rsa.pem&#39;</span>
<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>.<span class="ruby-identifier">new</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-string">&#39;rsa.pem&#39;</span>), <span class="ruby-string">&#39;my password&#39;</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
{
    EVP_PKEY *pkey;
    RSA *rsa;
    BIO *in = NULL;
    VALUE arg, pass;
    int type;

    TypedData_Get_Struct(self, EVP_PKEY, &amp;ossl_evp_pkey_type, pkey);
    if (pkey)
        rb_raise(rb_eTypeError, &quot;pkey already initialized&quot;);

    /* The RSA.new(size, generator) form is handled by lib/openssl/pkey.rb */
    rb_scan_args(argc, argv, &quot;02&quot;, &amp;arg, &amp;pass);
    if (argc == 0) {
        rsa = RSA_new();
        if (!rsa)
            ossl_raise(eRSAError, &quot;RSA_new&quot;);
        goto legacy;
    }

    pass = ossl_pem_passwd_value(pass);
    arg = ossl_to_der_if_possible(arg);
    in = ossl_obj2bio(&amp;arg);

    /* First try RSAPublicKey format */
    rsa = d2i_RSAPublicKey_bio(in, NULL);
    if (rsa)
        goto legacy;
    OSSL_BIO_reset(in);
    rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL);
    if (rsa)
        goto legacy;
    OSSL_BIO_reset(in);

    /* Use the generic routine */
    pkey = ossl_pkey_read_generic(in, pass);
    BIO_free(in);
    if (!pkey)
        ossl_raise(eRSAError, &quot;Neither PUB key nor PRIV key&quot;);

    type = EVP_PKEY_base_id(pkey);
    if (type != EVP_PKEY_RSA) {
        EVP_PKEY_free(pkey);
        rb_raise(eRSAError, &quot;incorrect pkey type: %s&quot;, OBJ_nid2sn(type));
    }
    RTYPEDDATA_DATA(self) = pkey;
    return self;

  legacy:
    BIO_free(in);
    pkey = EVP_PKEY_new();
    if (!pkey || EVP_PKEY_assign_RSA(pkey, rsa) != 1) {
        EVP_PKEY_free(pkey);
        RSA_free(rsa);
        ossl_raise(eRSAError, &quot;EVP_PKEY_assign_RSA&quot;);
    }
    RTYPEDDATA_DATA(self) = pkey;
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-export" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          export([cipher, password]) &rarr; PEM-format String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a PEM-encoding.</p>
<dl class="rdoc-list label-list"><dt>When the key contains public components only
<dd>
<p>Serializes it into an X.509 SubjectPublicKeyInfo. The parameters <em>cipher</em> and <em>password</em> are ignored.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN PUBLIC KEY-----
[...]
-----END PUBLIC KEY-----</pre>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> instead. This serializes the key into an X.509 SubjectPublicKeyInfo regardless of whether the key is a public key or a private key.</p>
</dd><dt>When the key contains private components, and no parameters are given
<dd>
<p>Serializes it into a PKCS #1 RSAPrivateKey.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN RSA PRIVATE KEY-----
[...]
-----END RSA PRIVATE KEY-----</pre>
</dd><dt>When the key contains private components, and <em>cipher</em> and <em>password</em> are given
<dd>
<p>Serializes it into a PKCS #1 RSAPrivateKey and encrypts it in OpenSSL’s traditional PEM encryption format. <em>cipher</em> must be a cipher name understood by <a href="../Cipher.html#method-c-new"><code>OpenSSL::Cipher.new</code></a> or an instance of <a href="../Cipher.html"><code>OpenSSL::Cipher</code></a>.</p>

<p>An encrypted PEM-encoded key will look like:</p>

<pre>-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,733F5302505B34701FC41F5C0746E4C0

[...]
-----END RSA PRIVATE KEY-----</pre>

<p>Note that this format uses MD5 to derive the encryption key, and hence will not be available on FIPS-compliant systems.</p>
</dd></dl>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the PKCS #1 RSAPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> (X.509 SubjectPublicKeyInfo) or <a href="PKey.html#method-i-private_to_pem"><code>private_to_pem</code></a> (PKCS #8 PrivateKeyInfo or EncryptedPrivateKeyInfo) instead.</p>

                              <div class="method-source-code" id="export-source">
            <pre>static VALUE
ossl_rsa_export(int argc, VALUE *argv, VALUE self)
{
    if (can_export_rsaprivatekey(self))
        return ossl_pkey_export_traditional(argc, argv, self, 0);
    else
        return ossl_pkey_export_spki(self, 0);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="RSA.html#method-i-to_pem">to_pem</a>, <a href="RSA.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-initialize_copy" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">initialize_copy</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
ossl_rsa_initialize_copy(VALUE self, VALUE other)
{
    EVP_PKEY *pkey;
    RSA *rsa, *rsa_new;

    TypedData_Get_Struct(self, EVP_PKEY, &amp;ossl_evp_pkey_type, pkey);
    if (pkey)
        rb_raise(rb_eTypeError, &quot;pkey already initialized&quot;);
    GetRSA(other, rsa);

    rsa_new = (RSA *)ASN1_dup((i2d_of_void *)i2d_RSAPrivateKey,
                              (d2i_of_void *)d2i_RSAPrivateKey,
                              (char *)rsa);
    if (!rsa_new)
        ossl_raise(eRSAError, &quot;ASN1_dup&quot;);

    pkey = EVP_PKEY_new();
    if (!pkey || EVP_PKEY_assign_RSA(pkey, rsa_new) != 1) {
        RSA_free(rsa_new);
        ossl_raise(eRSAError, &quot;EVP_PKEY_assign_RSA&quot;);
    }
    RTYPEDDATA_DATA(self) = pkey;

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-params" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          params &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!</p>

<p>Stores all parameters of key to the hash.  The hash has keys ‘n’, ‘e’, ‘d’, ‘p’, ‘q’, ‘dmp1’, ‘dmq1’, ‘iqmp’.</p>

<p>Don’t use :-)) (It’s up to you)</p>

                              <div class="method-source-code" id="params-source">
            <pre>static VALUE
ossl_rsa_get_params(VALUE self)
{
    OSSL_3_const RSA *rsa;
    VALUE hash;
    const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;

    GetRSA(self, rsa);
    RSA_get0_key(rsa, &amp;n, &amp;e, &amp;d);
    RSA_get0_factors(rsa, &amp;p, &amp;q);
    RSA_get0_crt_params(rsa, &amp;dmp1, &amp;dmq1, &amp;iqmp);

    hash = rb_hash_new();
    rb_hash_aset(hash, rb_str_new2(&quot;n&quot;), ossl_bn_new(n));
    rb_hash_aset(hash, rb_str_new2(&quot;e&quot;), ossl_bn_new(e));
    rb_hash_aset(hash, rb_str_new2(&quot;d&quot;), ossl_bn_new(d));
    rb_hash_aset(hash, rb_str_new2(&quot;p&quot;), ossl_bn_new(p));
    rb_hash_aset(hash, rb_str_new2(&quot;q&quot;), ossl_bn_new(q));
    rb_hash_aset(hash, rb_str_new2(&quot;dmp1&quot;), ossl_bn_new(dmp1));
    rb_hash_aset(hash, rb_str_new2(&quot;dmq1&quot;), ossl_bn_new(dmq1));
    rb_hash_aset(hash, rb_str_new2(&quot;iqmp&quot;), ossl_bn_new(iqmp));

    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private? &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Does this keypair contain a private key?</p>

                              <div class="method-source-code" id="private-3F-source">
            <pre>static VALUE
ossl_rsa_is_private(VALUE self)
{
    OSSL_3_const RSA *rsa;

    GetRSA(self, rsa);

    return RSA_PRIVATE(self, rsa) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private_decrypt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_decrypt(string)          &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_decrypt(string, padding) &rarr; String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Decrypt <code>string</code>, which has been encrypted with the public key, with the private key. <code>padding</code> defaults to <a href="RSA.html#PKCS1_PADDING"><code>PKCS1_PADDING</code></a>, which is known to be insecure but is kept for backwards compatibility.</p>

<p><strong>Deprecated in version 3.0</strong>. Consider using <a href="PKey.html#method-i-encrypt"><code>PKey::PKey#encrypt</code></a> and <a href="PKey.html#method-i-decrypt"><code>PKey::PKey#decrypt</code></a> instead.</p>

                              <div class="method-source-code" id="private_decrypt-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 439</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">private_decrypt</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">padding</span> = <span class="ruby-constant">PKCS1_PADDING</span>)
  <span class="ruby-identifier">n</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-string">&quot;incomplete RSA&quot;</span>
  <span class="ruby-identifier">private?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-string">&quot;private key needed.&quot;</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">data</span>, {
      <span class="ruby-string">&quot;rsa_padding_mode&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">translate_padding_mode</span>(<span class="ruby-identifier">padding</span>),
    })
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-identifier">$!</span>.<span class="ruby-identifier">message</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private_encrypt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_encrypt(string)          &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_encrypt(string, padding) &rarr; String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Encrypt <code>string</code> with the private key.  <code>padding</code> defaults to <a href="RSA.html#PKCS1_PADDING"><code>PKCS1_PADDING</code></a>, which is known to be insecure but is kept for backwards compatibility. The encrypted string output can be decrypted using <a href="RSA.html#method-i-public_decrypt"><code>public_decrypt</code></a>.</p>

<p><strong>Deprecated in version 3.0</strong>. Consider using <a href="PKey.html#method-i-sign_raw"><code>PKey::PKey#sign_raw</code></a> and <a href="PKey.html#method-i-verify_raw"><code>PKey::PKey#verify_raw</code></a>, and <a href="PKey.html#method-i-verify_recover"><code>PKey::PKey#verify_recover</code></a> instead.</p>

                              <div class="method-source-code" id="private_encrypt-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 373</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">private_encrypt</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">padding</span> = <span class="ruby-constant">PKCS1_PADDING</span>)
  <span class="ruby-identifier">n</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-string">&quot;incomplete RSA&quot;</span>
  <span class="ruby-identifier">private?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-string">&quot;private key needed.&quot;</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">sign_raw</span>(<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">string</span>, {
      <span class="ruby-string">&quot;rsa_padding_mode&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">translate_padding_mode</span>(<span class="ruby-identifier">padding</span>),
    })
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-identifier">$!</span>.<span class="ruby-identifier">message</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public? &rarr; true
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>The return value is always <code>true</code> since every private key is also a public key.</p>

                              <div class="method-source-code" id="public-3F-source">
            <pre>static VALUE
ossl_rsa_is_public(VALUE self)
{
    OSSL_3_const RSA *rsa;

    GetRSA(self, rsa);
    /*
     * This method should check for n and e.  BUG.
     */
    (void)rsa;
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_decrypt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_decrypt(string)          &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_decrypt(string, padding) &rarr; String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Decrypt <code>string</code>, which has been encrypted with the private key, with the public key.  <code>padding</code> defaults to <a href="RSA.html#PKCS1_PADDING"><code>PKCS1_PADDING</code></a> which is known to be insecure but is kept for backwards compatibility.</p>

<p><strong>Deprecated in version 3.0</strong>. Consider using <a href="PKey.html#method-i-sign_raw"><code>PKey::PKey#sign_raw</code></a> and <a href="PKey.html#method-i-verify_raw"><code>PKey::PKey#verify_raw</code></a>, and <a href="PKey.html#method-i-verify_recover"><code>PKey::PKey#verify_recover</code></a> instead.</p>

                              <div class="method-source-code" id="public_decrypt-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 396</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">public_decrypt</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">padding</span> = <span class="ruby-constant">PKCS1_PADDING</span>)
  <span class="ruby-identifier">n</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-string">&quot;incomplete RSA&quot;</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">verify_recover</span>(<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">string</span>, {
      <span class="ruby-string">&quot;rsa_padding_mode&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">translate_padding_mode</span>(<span class="ruby-identifier">padding</span>),
    })
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-identifier">$!</span>.<span class="ruby-identifier">message</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_encrypt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_encrypt(string)          &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_encrypt(string, padding) &rarr; String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Encrypt <code>string</code> with the public key.  <code>padding</code> defaults to <a href="RSA.html#PKCS1_PADDING"><code>PKCS1_PADDING</code></a>, which is known to be insecure but is kept for backwards compatibility. The encrypted string output can be decrypted using <a href="RSA.html#method-i-private_decrypt"><code>private_decrypt</code></a>.</p>

<p><strong>Deprecated in version 3.0</strong>. Consider using <a href="PKey.html#method-i-encrypt"><code>PKey::PKey#encrypt</code></a> and <a href="PKey.html#method-i-decrypt"><code>PKey::PKey#decrypt</code></a> instead.</p>

                              <div class="method-source-code" id="public_encrypt-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 418</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">public_encrypt</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">padding</span> = <span class="ruby-constant">PKCS1_PADDING</span>)
  <span class="ruby-identifier">n</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-string">&quot;incomplete RSA&quot;</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">data</span>, {
      <span class="ruby-string">&quot;rsa_padding_mode&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">translate_padding_mode</span>(<span class="ruby-identifier">padding</span>),
    })
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSAError</span>, <span class="ruby-identifier">$!</span>.<span class="ruby-identifier">message</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_key" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_key &rarr; rsanew
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new <a href="RSA.html"><code>RSA</code></a> instance that carries just the public key components.</p>

<p>This method is provided for backwards compatibility. In most cases, there is no need to call this method.</p>

<p>For the purpose of serializing the public key, to PEM or DER encoding of X.509 SubjectPublicKeyInfo format, check <a href="PKey.html#method-i-public_to_pem"><code>PKey#public_to_pem</code></a> and <a href="PKey.html#method-i-public_to_der"><code>PKey#public_to_der</code></a>.</p>

                              <div class="method-source-code" id="public_key-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 327</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">public_key</span>
  <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">public_to_der</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_crt_params" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          set_crt_params(dmp1, dmq1, iqmp) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sets <em>dmp1</em>, <em>dmq1</em>, <em>iqmp</em> for the <a href="RSA.html"><code>RSA</code></a> instance. They are calculated by <code>d mod (p - 1)</code>, <code>d mod (q - 1)</code> and <code>q^(-1) mod p</code> respectively.</p>

                            </div>


                          </div>

                  <div id="method-i-set_factors" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          set_factors(p, q) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sets <em>p</em>, <em>q</em> for the <a href="RSA.html"><code>RSA</code></a> instance.</p>

                            </div>


                          </div>

                  <div id="method-i-set_key" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          set_key(n, e, d) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sets <em>n</em>, <em>e</em>, <em>d</em> for the <a href="RSA.html"><code>RSA</code></a> instance.</p>

                            </div>


                          </div>

                  <div id="method-i-sign_pss" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sign_pss(digest, data, salt_length:, mgf1_hash:) &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Signs <em>data</em> using the Probabilistic Signature Scheme (RSA-PSS) and returns the calculated signature.</p>

<p><a href="RSAError.html"><code>RSAError</code></a> will be raised if an error occurs.</p>

<p>See <a href="RSA.html#method-i-verify_pss"><code>verify_pss</code></a> for the verification operation.</p>

<h3 id="method-i-sign_pss-label-Parameters">Parameters<span><a href="#method-i-sign_pss-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><em>digest</em>
<dd>
<p>A String containing the message digest algorithm name.</p>
</dd><dt><em>data</em>
<dd>
<p>A String. The data to be signed.</p>
</dd><dt><em>salt_length</em>
<dd>
<p>The length in octets of the salt. Two special values are reserved: <code>:digest</code> means the digest length, and <code>:max</code> means the maximum possible length for the combination of the private key and the selected message digest algorithm.</p>
</dd><dt><em>mgf1_hash</em>
<dd>
<p>The hash algorithm used in MGF1 (the currently supported mask generation function (MGF)).</p>
</dd></dl>

<h3 id="method-i-sign_pss-label-Example">Example<span><a href="#method-i-sign_pss-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&quot;Sign me!&quot;</span>
<span class="ruby-identifier">pkey</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2048</span>)
<span class="ruby-identifier">signature</span> = <span class="ruby-identifier">pkey</span>.<span class="ruby-identifier">sign_pss</span>(<span class="ruby-string">&quot;SHA256&quot;</span>, <span class="ruby-identifier">data</span>, <span class="ruby-value">salt_length:</span> <span class="ruby-value">:max</span>, <span class="ruby-value">mgf1_hash:</span> <span class="ruby-string">&quot;SHA256&quot;</span>)
<span class="ruby-identifier">pub_key</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">pkey</span>.<span class="ruby-identifier">public_to_der</span>)
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">pub_key</span>.<span class="ruby-identifier">verify_pss</span>(<span class="ruby-string">&quot;SHA256&quot;</span>, <span class="ruby-identifier">signature</span>, <span class="ruby-identifier">data</span>,
                        <span class="ruby-value">salt_length:</span> <span class="ruby-value">:auto</span>, <span class="ruby-value">mgf1_hash:</span> <span class="ruby-string">&quot;SHA256&quot;</span>) <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="sign_pss-source">
            <pre>static VALUE
ossl_rsa_sign_pss(int argc, VALUE *argv, VALUE self)
{
    VALUE digest, data, options, kwargs[2], signature;
    static ID kwargs_ids[2];
    EVP_PKEY *pkey;
    EVP_PKEY_CTX *pkey_ctx;
    const EVP_MD *md, *mgf1md;
    EVP_MD_CTX *md_ctx;
    size_t buf_len;
    int salt_len;

    if (!kwargs_ids[0]) {
        kwargs_ids[0] = rb_intern_const(&quot;salt_length&quot;);
        kwargs_ids[1] = rb_intern_const(&quot;mgf1_hash&quot;);
    }
    rb_scan_args(argc, argv, &quot;2:&quot;, &amp;digest, &amp;data, &amp;options);
    rb_get_kwargs(options, kwargs_ids, 2, 0, kwargs);
    if (kwargs[0] == ID2SYM(rb_intern(&quot;max&quot;)))
        salt_len = -2; /* RSA_PSS_SALTLEN_MAX_SIGN */
    else if (kwargs[0] == ID2SYM(rb_intern(&quot;digest&quot;)))
        salt_len = -1; /* RSA_PSS_SALTLEN_DIGEST */
    else
        salt_len = NUM2INT(kwargs[0]);
    mgf1md = ossl_evp_get_digestbyname(kwargs[1]);

    pkey = GetPrivPKeyPtr(self);
    buf_len = EVP_PKEY_size(pkey);
    md = ossl_evp_get_digestbyname(digest);
    StringValue(data);
    signature = rb_str_new(NULL, (long)buf_len);

    md_ctx = EVP_MD_CTX_new();
    if (!md_ctx)
        goto err;

    if (EVP_DigestSignInit(md_ctx, &amp;pkey_ctx, md, NULL, pkey) != 1)
        goto err;

    if (EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) != 1)
        goto err;

    if (EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, salt_len) != 1)
        goto err;

    if (EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, mgf1md) != 1)
        goto err;

    if (EVP_DigestSignUpdate(md_ctx, RSTRING_PTR(data), RSTRING_LEN(data)) != 1)
        goto err;

    if (EVP_DigestSignFinal(md_ctx, (unsigned char *)RSTRING_PTR(signature), &amp;buf_len) != 1)
        goto err;

    rb_str_set_len(signature, (long)buf_len);

    EVP_MD_CTX_free(md_ctx);
    return signature;

  err:
    EVP_MD_CTX_free(md_ctx);
    ossl_raise(eRSAError, NULL);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_der" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_der &rarr; DER-format String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a DER-encoding.</p>

<p>See <a href="RSA.html#method-i-to_pem"><code>to_pem</code></a> for details.</p>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the PKCS #1 RSAPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_der"><code>public_to_der</code></a> or <a href="PKey.html#method-i-private_to_der"><code>private_to_der</code></a> instead.</p>

                              <div class="method-source-code" id="to_der-source">
            <pre>static VALUE
ossl_rsa_to_der(VALUE self)
{
    if (can_export_rsaprivatekey(self))
        return ossl_pkey_export_traditional(0, NULL, self, 1);
    else
        return ossl_pkey_export_spki(self, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_pem" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_pem([cipher, password]) &rarr; PEM-format String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a PEM-encoding.</p>
<dl class="rdoc-list label-list"><dt>When the key contains public components only
<dd>
<p>Serializes it into an X.509 SubjectPublicKeyInfo. The parameters <em>cipher</em> and <em>password</em> are ignored.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN PUBLIC KEY-----
[...]
-----END PUBLIC KEY-----</pre>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> instead. This serializes the key into an X.509 SubjectPublicKeyInfo regardless of whether the key is a public key or a private key.</p>
</dd><dt>When the key contains private components, and no parameters are given
<dd>
<p>Serializes it into a PKCS #1 RSAPrivateKey.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN RSA PRIVATE KEY-----
[...]
-----END RSA PRIVATE KEY-----</pre>
</dd><dt>When the key contains private components, and <em>cipher</em> and <em>password</em> are given
<dd>
<p>Serializes it into a PKCS #1 RSAPrivateKey and encrypts it in OpenSSL’s traditional PEM encryption format. <em>cipher</em> must be a cipher name understood by <a href="../Cipher.html#method-c-new"><code>OpenSSL::Cipher.new</code></a> or an instance of <a href="../Cipher.html"><code>OpenSSL::Cipher</code></a>.</p>

<p>An encrypted PEM-encoded key will look like:</p>

<pre>-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,733F5302505B34701FC41F5C0746E4C0

[...]
-----END RSA PRIVATE KEY-----</pre>

<p>Note that this format uses MD5 to derive the encryption key, and hence will not be available on FIPS-compliant systems.</p>
</dd></dl>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the PKCS #1 RSAPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> (X.509 SubjectPublicKeyInfo) or <a href="PKey.html#method-i-private_to_pem"><code>private_to_pem</code></a> (PKCS #8 PrivateKeyInfo or EncryptedPrivateKeyInfo) instead.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="RSA.html#method-i-export">export</a>
                            </div>
                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s([cipher, password]) &rarr; PEM-format String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a PEM-encoding.</p>
<dl class="rdoc-list label-list"><dt>When the key contains public components only
<dd>
<p>Serializes it into an X.509 SubjectPublicKeyInfo. The parameters <em>cipher</em> and <em>password</em> are ignored.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN PUBLIC KEY-----
[...]
-----END PUBLIC KEY-----</pre>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> instead. This serializes the key into an X.509 SubjectPublicKeyInfo regardless of whether the key is a public key or a private key.</p>
</dd><dt>When the key contains private components, and no parameters are given
<dd>
<p>Serializes it into a PKCS #1 RSAPrivateKey.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN RSA PRIVATE KEY-----
[...]
-----END RSA PRIVATE KEY-----</pre>
</dd><dt>When the key contains private components, and <em>cipher</em> and <em>password</em> are given
<dd>
<p>Serializes it into a PKCS #1 RSAPrivateKey and encrypts it in OpenSSL’s traditional PEM encryption format. <em>cipher</em> must be a cipher name understood by <a href="../Cipher.html#method-c-new"><code>OpenSSL::Cipher.new</code></a> or an instance of <a href="../Cipher.html"><code>OpenSSL::Cipher</code></a>.</p>

<p>An encrypted PEM-encoded key will look like:</p>

<pre>-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,733F5302505B34701FC41F5C0746E4C0

[...]
-----END RSA PRIVATE KEY-----</pre>

<p>Note that this format uses MD5 to derive the encryption key, and hence will not be available on FIPS-compliant systems.</p>
</dd></dl>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the PKCS #1 RSAPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> (X.509 SubjectPublicKeyInfo) or <a href="PKey.html#method-i-private_to_pem"><code>private_to_pem</code></a> (PKCS #8 PrivateKeyInfo or EncryptedPrivateKeyInfo) instead.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="RSA.html#method-i-export">export</a>
                            </div>
                          </div>

                  <div id="method-i-verify_pss" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          verify_pss(digest, signature, data, salt_length:, mgf1_hash:) &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Verifies <em>data</em> using the Probabilistic Signature Scheme (RSA-PSS).</p>

<p>The return value is <code>true</code> if the signature is valid, <code>false</code> otherwise. <a href="RSAError.html"><code>RSAError</code></a> will be raised if an error occurs.</p>

<p>See <a href="RSA.html#method-i-sign_pss"><code>sign_pss</code></a> for the signing operation and an example code.</p>

<h3 id="method-i-verify_pss-label-Parameters">Parameters<span><a href="#method-i-verify_pss-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><em>digest</em>
<dd>
<p>A String containing the message digest algorithm name.</p>
</dd><dt><em>data</em>
<dd>
<p>A String. The data to be signed.</p>
</dd><dt><em>salt_length</em>
<dd>
<p>The length in octets of the salt. Two special values are reserved: <code>:digest</code> means the digest length, and <code>:auto</code> means automatically determining the length based on the signature.</p>
</dd><dt><em>mgf1_hash</em>
<dd>
<p>The hash algorithm used in MGF1.</p>
</dd></dl>

                              <div class="method-source-code" id="verify_pss-source">
            <pre>static VALUE
ossl_rsa_verify_pss(int argc, VALUE *argv, VALUE self)
{
    VALUE digest, signature, data, options, kwargs[2];
    static ID kwargs_ids[2];
    EVP_PKEY *pkey;
    EVP_PKEY_CTX *pkey_ctx;
    const EVP_MD *md, *mgf1md;
    EVP_MD_CTX *md_ctx;
    int result, salt_len;

    if (!kwargs_ids[0]) {
        kwargs_ids[0] = rb_intern_const(&quot;salt_length&quot;);
        kwargs_ids[1] = rb_intern_const(&quot;mgf1_hash&quot;);
    }
    rb_scan_args(argc, argv, &quot;3:&quot;, &amp;digest, &amp;signature, &amp;data, &amp;options);
    rb_get_kwargs(options, kwargs_ids, 2, 0, kwargs);
    if (kwargs[0] == ID2SYM(rb_intern(&quot;auto&quot;)))
        salt_len = -2; /* RSA_PSS_SALTLEN_AUTO */
    else if (kwargs[0] == ID2SYM(rb_intern(&quot;digest&quot;)))
        salt_len = -1; /* RSA_PSS_SALTLEN_DIGEST */
    else
        salt_len = NUM2INT(kwargs[0]);
    mgf1md = ossl_evp_get_digestbyname(kwargs[1]);

    GetPKey(self, pkey);
    md = ossl_evp_get_digestbyname(digest);
    StringValue(signature);
    StringValue(data);

    md_ctx = EVP_MD_CTX_new();
    if (!md_ctx)
        goto err;

    if (EVP_DigestVerifyInit(md_ctx, &amp;pkey_ctx, md, NULL, pkey) != 1)
        goto err;

    if (EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) != 1)
        goto err;

    if (EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, salt_len) != 1)
        goto err;

    if (EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, mgf1md) != 1)
        goto err;

    if (EVP_DigestVerifyUpdate(md_ctx, RSTRING_PTR(data), RSTRING_LEN(data)) != 1)
        goto err;

    result = EVP_DigestVerifyFinal(md_ctx,
                                   (unsigned char *)RSTRING_PTR(signature),
                                   RSTRING_LEN(signature));

    switch (result) {
      case 0:
        ossl_clear_error();
        EVP_MD_CTX_free(md_ctx);
        return Qfalse;
      case 1:
        EVP_MD_CTX_free(md_ctx);
        return Qtrue;
      default:
        goto err;
    }

  err:
    EVP_MD_CTX_free(md_ctx);
    ossl_raise(eRSAError, NULL);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-translate_padding_mode" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">translate_padding_mode</span><span
                                class="method-args">(num)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="translate_padding_mode-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 456</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">translate_padding_mode</span>(<span class="ruby-identifier">num</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">num</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">PKCS1_PADDING</span>
    <span class="ruby-string">&quot;pkcs1&quot;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">SSLV23_PADDING</span>
    <span class="ruby-string">&quot;sslv23&quot;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">NO_PADDING</span>
    <span class="ruby-string">&quot;none&quot;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">PKCS1_OAEP_PADDING</span>
    <span class="ruby-string">&quot;oaep&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>, <span class="ruby-string">&quot;unsupported padding mode&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

